<template>
  <view class="container">
    <view class='has-info' v-if="addressList.length > 0">
      <view bindtap="{{type == 0?'goAddressDetail':'selectAddress'}}" class='info-item'  v-for="item in addressList" :key="item.id">
        <view class="selected" v-if="type == 1">
          <image v-if="item.id == nowAddress" class="img" src="/images/icon/gou-red.png"></image>
          <image v-else class="img" src="/images/icon/gou-gray.png"></image>
        </view>
        <view class="info-wrap">
          <view class="addr">
            <view class="top">{{item.address}}</view>
            <view class="text">{{item.full_region}}</view>
          </view>
          <view class="name">
            <view class="text">{{item.name}} {{item.mobile}}</view>
            <view class="default" v-if="item.is_default">默认</view>
          </view>
        </view>
        <view class="edit-wrap" data-addressid="{{item.id}}" catchtap='goAddressDetail'>
          <image class="img" src="/images/icon/edit.png"></image>
        </view>
      </view>
    </view>
    <view class="no-info" v-else>
      <image src="/images/icon/position-deny.png" class="img"></image>
      <view class="text">没有地址信息</view>
    </view>
    <view class="btn-wrap" @click="addAddress">
      <view class="btn">新增收货地址</view>
    </view>
  </view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad,
		onShow,
		onPullDownRefresh,
		onReachBottom
	} from "@dcloudio/uni-app";
	import request from "/common/api.js"


	const model = ref([])
	const status = ref("more")
	const totalPage = ref(0)
  const nowAddress=ref(null)

  const  addressList=ref([])
  const  type=ref(0)
	const searchObject = ref({
		name: "",
		no: 1,
		size: 10
	})

  const addAddress=()=>{

  }

    const serverUrl ="/appRole/search";
	const initData = () => {
		searchObject.value.no = 1;
		request.loadPostCallback(serverUrl, searchObject.value, (res) => {
			if (res.code === 200) {
				model.value = res.data;
				checkMore(res)
			}
			uni.stopPullDownRefresh();
		})
	}

	onShow(() => {
		searchObject.value.no = 1;
		request.loadPostCallback(serverUrl, searchObject.value, (res) => {
			if (res.code === 200) {
				model.value = res.data;
				checkMore(res)
			}
		})
	})

	onPullDownRefresh(() => {
		initData();
	})

	onReachBottom(() => {
		searchObject.value.no = searchObject.value.no + 1;
		request.loadPostCallback(serverUrl, searchObject.value, (res) => {
			if (res.code === 200) {
				if (res.data) {
					model.value = model.value.concat(res.data);
				}

				checkMore(res)
			}
		})
	});

	const checkMore = (res) => {
	    totalPage.value = res.totalPage;
		if (searchObject.value.no <= res.totalPage) {
			status.value = "loading";
		} else {
			status.value = "noMore";
			return;
		}

	}

	const search = () => {
		initData();
	}
	const input = () => {

	}
</script>

<style>
.container {
  display: flex;
  align-items: stretch;
  overflow-x: hidden;
}

.has-info {
  display: flex;
  flex-direction: column;
  padding: 30rpx;
}

.has-info .info-item {
  padding: 30rpx 0;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  background: #fff;
  border-radius: 10rpx;
  box-shadow: 2rpx 8rpx 18rpx #f1f1f1;
  margin-bottom: 24rpx;
  position: relative;
}

.has-info .info-item .edit-wrap{
  padding: 30rpx;
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.has-info .info-item .edit-wrap .img{
  width: 42rpx;
  height: 42rpx;
}

.has-info .info-item .selected {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30rpx 0 30rpx 30rpx;
}

.has-info .info-item .selected .img {
  width: 40rpx;
  height: 40rpx;
}

.has-info .info-item .info-wrap{
  display: flex;
  flex-direction: column;
  padding-left: 30rpx;
}

.has-info .info-item .info-wrap .addr {
  display: flex;
  flex-direction: column;
  margin-bottom: 10rpx;
}

.has-info .info-item .info-wrap .addr .top {
  font-size: 30rpx;
  font-weight: 500;
  margin-bottom: 4rpx;
}

.has-info .info-item .info-wrap .addr .text {
  font-size: 24rpx;
  color: #777;
}

.has-info .info-item .info-wrap .addr .img-wrap {
  width: 44rpx;
  height: 44rpx;
  margin-right: 10rpx;
}

.has-info .info-item .info-wrap .name {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.has-info .info-item .info-wrap .name .img-wrap {
  width: 44rpx;
  height: 44rpx;
  margin-right: 10rpx;
}

.has-info .info-item .info-wrap .name .img {
  width: 42rpx;
  height: 42rpx;
}

.has-info .info-item .info-wrap .name .default {
  font-size: 22rpx;
  color: #ff3456;
  background: #faedef;
  text-align: center;
  padding: 2rpx 10rpx;
  border-radius: 4rpx;
}

.has-info .info-item .info-wrap .name .text {
  font-size: 26rpx;
  margin-right: 10rpx;
}

.has-info .info-item .id-wrap {
  display: flex;
  flex-direction: column;
}

.has-info .info-item .id-wrap .ids {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 26rpx;
  color: #5d6777;
  margin-bottom: 8rpx;
}

.has-info .info-item .id-wrap .ids .id-name {
  margin-right: 20rpx;
}

.has-info .info-item .id-wrap .no-ids {
  font-size: 26rpx;
  color: #ffbb12;
}

.has-info .add-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border-radius: 10rpx;
  box-shadow: 2rpx 8rpx 18rpx #f1f1f1;
  margin-bottom: 24rpx;
  padding: 30rpx 0;
}

.has-info .add-btn .icon-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 40rpx;
  height: 40rpx;
  margin-right: 8rpx;
}

.has-info .add-btn .icon-wrap .img {
  width: 40rpx;
  height: 40rpx;
}

.has-info .add-btn .text {
  font-size: 28rpx;
  color: #ffc310;
}

.no-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-top: 300rpx;
}

.no-info .img {
  width: 100rpx;
  height: 100rpx;
  margin-bottom: 30rpx;
}

.no-info .text {
  font-size: 30rpx;
  color: #999;
  text-align: center;
  margin-bottom: 30rpx;
}

.no-info .add-btn {
  color: #192841;
  /* background: #ff3456; */
  background: linear-gradient(to right, #f8dd66, #fae277);
  border-radius: 100px;
  width: 400rpx;
  height: 80rpx;
  line-height: 80rpx;
  text-align: center;
  font-size: 28rpx;
  margin: 0 auto;
}



.btn-wrap {
  position: fixed;
  bottom: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.btn-wrap .btn {
  width: 100%;
  background: linear-gradient(to right, #ff3456, #ff347d);
  color: #fff;
  font-size: 28rpx;
  text-align: center;
  height: 110rpx;
  line-height: 100rpx;
}
</style>
